// put your implementation here
  
  
        
import java.util.*;

public class Tree extends Node    
{
	Tree tree = new Tree();
	public Tree left, mid , right; 
	public Tree (int Key ,String Box)
	{
		super(Key, Box);
		left = new Tree();
		mid = new Tree();
		right = new Tree();
	}

	public Tree() {
		super();
	}
	
	public void insertRoot(int K , String V)
	{
		
		tree.Key = K;
		tree.Box = V;
		
	}
	
	
	public boolean haveChild(){
		if(left != null || mid != null || right != null){
			
			if(left.getKey() > 0 || mid.getKey() > 0 || right.getKey() > 0)			
				return true;
			else
				return false;
		}
		else
			return false;
		
	}
	
	private String printchild(Tree child){
		String retString = "";
		
		if(child.haveChild()){
			retString += toString() + " -- "+ child.toString() + "\n";
			retString += child.print();
		}else{
			if(child.getKey() > 0)
				retString += toString() + " -- " + child.toString() + "\n";
		}
		return retString;
	}
	
	public String print()
	{	
		String retString = "";	
		if(haveChild()){	
			retString += printchild(left);
			retString += printchild(mid);
			retString += printchild(right);
		}else{
		}
		
		
		return retString;
	}
   
   //put it inside a class
  public int getSmallest(Tree child,int current_smallest_key)
  {
       if (haveChild())
       {         
           return Math.min(current_smallest_key, child.look_for_smallest());
       }
       else if
       {
           return Math.min(current_smallest_key, child.key);
       }
  }


  public int look_for_smallest()
  {
    //where's your default case?
    //int current_smallest = this.key;
    If (haveChild())
       {
         //uh oh, these lines below will be big trouble because it calls the recursive method over and over again,
         //try storing it, say
         //int left_smallest = getSmallest(this.left, current_smallest);
         //int mid_smallest = getSmallest(this.mid, current_smallest);
         
         //and then compare which one is the smallest, return the smallest number
         
         if (getSmallest(tree.left) > getSmallest(tree.mid)&& getSmallest(tree.left) > getSmallest(tree.right))
         {
            return tree.left;
         }
           
         else if (getSmallest(tree.mid)>getSmallest(tree.right)
         {
            return tree.mid;
         }
         
         else
         {
           return tree.right;
         }
       }
      
  }
 
	
}
 